package com.panda.QQserver.service;

import java.util.HashMap;
import java.util.Iterator;

public class ManageClientThreads {
    private static HashMap<String,ServerConnectClientThread> hm = new HashMap<>();

    public static void add(String userId, ServerConnectClientThread  serverConnectClientThread){
        hm.put(userId,serverConnectClientThread);

    }

    public static ServerConnectClientThread get(String userId) {
        return hm.get(userId);
    }

    //返回用户在线列表
    public static String getOnlineUsers(){
        Iterator<String> iterator = hm.keySet().iterator();
        String list=" ";
        while(iterator.hasNext()){
            String key = iterator.next();
            ServerConnectClientThread serverConnectClientThread = hm.get(key);
            String id = serverConnectClientThread.getUserId();
            list+=id+" ";
        }
        return list;
    }

    //删除某个线程
    public static void removeThread(String userId) {
        hm.remove(userId);
    }

    //得到某个线程
    public static ServerConnectClientThread getThread(String userId) {
        return hm.get(userId);
    }

    //返回整个hashmap
    public static HashMap<String,ServerConnectClientThread> getHm(){
        return hm;
    }
}
